#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <math.h>
#include <time.h>
#define ERROR_CHECK(ret, num, msg) \
    {                              \
        if (ret == num)            \
        {                          \
            perror(msg);           \
            exit(1);               \
        }                          \
    }
int main(int argc, char *argv[])
{
    int fd1 = open(argv[1], O_RDWR);
    ERROR_CHECK(-1, fd1, "open");
    char buf[1024] = {0};
    srand(time(NULL));
    int ret = 0;
    int fd2 = open(argv[2], O_WRONLY | O_CREAT | O_TRUNC, 0664);
    int i = 0;
    while (ret = read(fd1, buf, sizeof(buf) - 1))
    {
        write(fd2, buf, ret);
        i++;
        if (i > 60 && i<70)
        {
            for (size_t i = 0; i < 1024; i++)
            {
                buf[i] = 1 + rand() % 255;
            }         
            write(fd2, buf, 1);
        }
    }

    close(fd1);
    close(fd2);
    return 0;
}
